#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/2/6 16:23
# ===========================================
#       题目名称： 11.盛最多水的容器
#       题目地址： https://leetcode.cn/problems/container-with-most-water/
#       题目描述： https://note.youdao.com/s/LWYgPSzT
# ===========================================


class Solution:

    def maxArea(self, height):
        """
            找最大的
                1,8,6,2,5,4,8,3,7
        """
        max_value = 0  # 最大值
        left, right = 0, len(height) - 1  # 两个指针 左右
        while left < right:
            if height[left] > height[right]:
                max_value = max(max_value, height[right] * (right - left))
                right -= 1
            else:
                max_value = max(max_value, height[left] * (right - left))
                left += 1
        return max_value

    def maxArea2(self, height):
        """
            两层for循环求最大值
        """
        max_value = 0
        for i in range(len(height) - 1):
            for j in range(1, len(height)):
                current_value = 0
                if height[i] >= height[j]:
                    current_value = height[j] * (j - i)
                else:
                    current_value = height[i] * (j - i)
                max_value = max(max_value, current_value)
        return max_value


if __name__ == '__main__':
    s = Solution()
    print('[1,8,6,2,5,4,8,3,7] =>' + str(s.maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7])))  # 49
    print(' [1,1] => ' + str(s.maxArea([1, 1])))  # 1
    print(' [1,2,1] => ' + str(s.maxArea([1, 2, 1])))  # 2
